<template>
  <div class="user-avator-dropdown">
    <Dropdown @on-click="handleClick">
      <Badge>
        <Avatar style="background-color:rgb(45, 140, 240)" icon="ios-person" size="small"/>
      </Badge>
      <Icon :size="18" type="md-arrow-dropdown"></Icon>
      <DropdownMenu slot="list">
        <DropdownItem name="logout">退出登录</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
import './user.less'
import { mapActions } from 'vuex'
export default {
  name: 'User',
  props: {
    userAvator: {
      type: String,
      default: ''
    },
    messageUnreadCount: {
      type: Number,
      default: 0
    }
  },
  methods: {
    ...mapActions([
      'handleLogOut'
    ]),
    logout () {
			this.$Modal.confirm({
				title: this.$t('messageTip.tip'),
				content: '<p>'+ this.$t('messageTip.confirm') +'</p>',
				onOk: () => {
					this.handleLogOut().then(() => {
					  this.$router.push({
					    name: 'index'
					  })
					})
				}
			});
    },
    message () {
      this.$router.push({
        name: 'messagePage'
      })
    },
    handleClick (name) {
      switch (name) {
        case 'logout': this.logout()
          break
        case 'message': this.message()
          break
      }
    }
  }
}
</script>
